<?php

class ArticleButtonColumn extends CButtonColumn {

    public $template = '{update}';
    public $buttons = array('update', 'inactive', 'active');

    protected function renderButton($id, $button, $row, $data) {
        if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row' => $row, 'data' => $data)))
            return;
        $url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data' => $data, 'row' => $row)) : '#';
        //$click = isset($button['onclick']) ? str_replace("@url", "'" . $url . "'", $button['onclick']) : '';
        $title = isset($button['title']) ? $button['title'] : '';
        $dialogWidth = isset($button['dialog-width']) ? $button['dialog-width'] : '';
        $dialogHeight = isset($button['dialog-height']) ? $button['dialog-height'] : '';
        $isTrash = isset($button['isTrash']) ? $this->evaluateExpression($button['isTrash'], array('data' => $data, 'row' => $row)) : '';
        $canComment = isset($button['canComment']) ? $this->evaluateExpression($button['canComment'], array('data' => $data, 'row' => $row)) : '';
        if ($isTrash == LGConstant::TRASHED_STATUS) {
            switch ($id) {
                //article
                case 'update':
                    echo Html::buttonInGrid('linkEditArticle', '', '', $title, 'icon edit', '', '', array('onclick'=>'window.location.href=\''. $url .'\''));
                    break;
                case 'restore':
                    echo Html::buttonInGrid('linkRestore', '', 'Restore', '', 'icon restore', '', '',  array('onclick'=>'LGCMS.ajaxCallback("' . $url . '")'));
                    break;
                case 'delete_forever':
                    echo Html::buttonPopup('linkDeleteForever', '', $url, '', 'Foster City Lions', 'icon delete button update-dialog-open-link', '500', '300');
                    break;
                case 'view_comment':
                    if ($canComment == LGConstant::CAN_COMMENT) {
                        echo Html::buttonInGrid('linkViewComment', $url, 'View Comment', $title, 'icon viewcomment update-dialog-open-link', $dialogWidth, $dialogHeight);
                    }
                    break;
            }
        } else {
            if ($id == 'update') {
                echo Html::buttonInGrid('linkEditArticle', '', '', $title, 'icon edit', '', '', array('onclick'=>'window.location.href=\''. $url .'\''));
            }
            if ($id == 'view_comment' && $canComment == LGConstant::CAN_COMMENT) {
                echo Html::buttonInGrid('linkViewComment', $url, 'View Comment', $title, 'icon viewcomment update-dialog-open-link', $dialogWidth, $dialogHeight);
            }
        }
    }

}

?>